function e(e, t) {
	if (e && t) {
		for (var a = e.split("."), o = t.split("."), i = Math.min(a.length, o.length), n = 0, s = 0; n < i && 0 == (s =
				parseInt(a[n]) - parseInt(o[n]));) n++;
		return (s = 0 != s ? s : a.length - o.length) >= 0;
	}
	return console.log("版本号不能为空"), !1;
}

var t, a = function(e) {
		return e && e.__esModule ? e : {
			default: e
		};
	}(require("../../../utils/tools.js")),
	o = getApp();


Page({
	data: {
		detail_list_type:0,
		details:[],
		ckShow: false,
		current: 0,
		swiper: {
			indicatorDots: false, //把true改为false就可以隐藏起来
			autoplay: false,
			interval: 5000,
			duration: 1000

		},
		bnrUrl: [{
			"url": "../../images/chiken_level/d1.png"
		}, {
			"url": "../../images/chiken_level/d2.png"
		}, {
			"url": "../../images/chiken_level/d3.png"
		}, {
			"url": "../../images/chiken_level/d4.png"
		}],
		friend_list_type: 0,
		request: 1,
		self_i: "__",
		self_s: "__",
		bag_i: "__",
		bag_s: "__",
		egg_i: "__",
		egg_s: "__",
		fruit_i: "__",
		fruit_s: "__",
		setTimeself: "",
		bagTimeself: "",
		eggTimeself: "",
		fruitTimeself: "",
		self_yield_ad_water_show: !1,
		self_water_id: 0,
		videoAd: "",
		interstitialAd: "",
		hasVideoAd: !1,
		bagShow: !1,
		red_open: 1,
		egg_open: 1,
		red_money: "",
		receive_bag_show: !1,
		invite_red_show: !1,
		least_water: 0,
		pageName: "index",
		welfare_show: !1,
		showAddMeBtn: !1,
		audit_model: !0,

		background: "/bh_farm/images/bg_normal/bg1.svg", //背景图片
		editTrue: false,
		feedTrue: false,
		fridesTrue: false,
	},
	swiperAdd: function(event) {
		var next = event.currentTarget.dataset.current + 1;
		var len = event.currentTarget.dataset.len;

		if (next >= len) return false;
		this.setData({
			current: next,
		})

	},
	swiperSub: function(event) {
		var last = event.currentTarget.dataset.current - 1;
		if (last < 0) return false;
		this.setData({
			current: last,
		})
	},
	switchDetail: function(event) {
		let type = event.currentTarget.dataset.i;
		this.setData({
			detail_list_type: type,
		})
		if(type==0){
			this.getDetail('water')
		}else if(type==1){
			this.getDetail('fruit')
		}

	},
	switchFl: function(event) {


		this.setData({
			friend_list_type: event.currentTarget.dataset.i,
		})


	},
	jumpPage: function() {
		wx.navigateTo({
			url: '/bh_farm/pages/strategy/strategy'
		})
	},

	jumpRecruit: function() {
		wx.navigateTo({
			url: '/bh_farm/pages/recruit/recruit'
		})
	},
	jumpDynamic: function() {
		var that = this;
		if (that.data.editTrue == true) {
			that.setData({
				editTrue: false,
			})

		} else {
			that.setData({
				editTrue: true,
			})
		}
		that.getDetail('water')
	},
	pumgClose: function() {
		var that = this;
		that.setData({
			detail_list_type: 0,
		})

		if (that.data.editTrue == true) {
			that.setData({
				editTrue: false,
			})
		}
	},

	jumpDtai: function() {
		var that = this;
		if (that.data.feedTrue == true) {
			that.setData({
				feedTrue: false,
			})

		} else {
			that.setData({
				feedTrue: true,
			})
		}
	},

	pumgCloseone: function() {
		var that = this;
		if (that.data.feedTrue == true) {
			that.setData({
				feedTrue: false,
			})
		}
	},

	jumpFrides: function() {
		var that = this;
		if (that.data.fridesTrue == true) {
			that.setData({
				fridesTrue: false,
			})

		} else {
			that.setData({
				fridesTrue: true,
			})
		}
	},
	closefrides: function() {
		var that = this;
		if (that.data.fridesTrue == true) {
			that.setData({
				fridesTrue: false,
			})
		}
	},
	onLoad: function(e) {
		t = this, this.clearTime(), e.parent_id && wx.setStorageSync("parent_id", e.parent_id),
			e.scene && wx.setStorageSync("parent_id", decodeURIComponent(e.scene));
		

	},
	getLoginBonus(){
		var o = {
			contrl:'sigin',
			action:'getLoginBonus',
			token: wx.getStorageSync("token")
		};
		a.default.request(o, function(a) {
			debugger
		});
	},
	getDetail(contr){
		this.setData({
			details: [],
		})
		var o = {
			action: "consume",
			contr: contr,
			token: wx.getStorageSync("token")
		};
		var that = this;
		a.default.request(o, function(a) {
			
			var detail = []
			if(contr=='water'){
				for(var i in a.info.water_record){
								 var item = {'date':i,'record':a.info.water_record[i]}
								detail.push(item)
				}
			}else if(contr=='fruit'){
				for(var i in a.info.fruit_record){
								 var item = {'date':i,'record':a.info.fruit_record[i]}
								detail.push(item)
				}
			}
			
			 console.log(JSON.stringify(detail))
		
			that.setData({
				details: detail
			})
		});
	},

	openCkShow: function() {

		this.setData({
			ckShow: true,
		})
	},
	closeCkShow: function() {

		this.setData({
			ckShow: false,
		})
	},
	pushset() {
		wx.navigateTo({
			url: '/bh_farm/pages/goods/goods',
		})
	},
	pushset2() {
		wx.navigateTo({
			url: '/bh_farm/pages/exchange/exchange',
		})
	},
	navigatorSwitch: function(e) {
		var t = e.detail.pageName;
		if (t != this.data.pageName) {
			if ("mine" == t) a = "/bh_farm/pages/my/my";
			else if ("recruit" == t) a = "/bh_farm/pages/recruit/recruit";
			else if ("tx" == t) a = "/bh_farm/pages/tx/tx";
			else if ("pdd" == t) a = "/bh_farm/pages/pdd/pdd";
			else if ("db" == t) var a = "/bh_farm/pages/treasure/treasure";
			wx.redirectTo({
				url: a
			});
		}
	},
	gotoTelephoneBill: function() {
		wx.navigateTo({
			url: "/bh_farm/pages/exchange/exchange"
		});
	},
	onClickAddToMinProgramCloseBtn: function() {
		wx.setStorageSync("showAddMeFlag" + this.data.time, !0), this.setData({
			showAddMeBtn: !1
		});
	},
	onReady: function() {
		var o = {
			action: "index",
			contr: "home",
			token: wx.getStorageSync("token")
		};
		a.default.request(o, function(a) {
			//处理导航
			var item = {
				"pageName": "tx",
				"text": "探险",
				"iconPath": "https://www.shangjinya.com/addons/bh_farm/template/static/images/xcx/a17.png",
				"selectedIconPath": "https://www.shangjinya.com/addons/bh_farm/template/static/images/xcx/a15.png",
				"index": 1,
				"visible": true
			}
			var tabs = a.info.list
			var newTabs = [tabs[0],item, tabs[3], tabs[4]]
			a.info.list = newTabs
			//处理导航
	
			t.setData(a.info), wx.getStorageSync("showAddMeFlag" + a.info.time) || t.setData({
				showAddMeBtn: !0
			}), wx.setNavigationBarTitle({
				title: a.info.xcx_title
			}), wx.createInterstitialAd && a.info.screen_ad && "" == t.data.interstitialAd && (t.data.interstitialAd = wx.createInterstitialAd({
				adUnitId: a.info.screen_ad
			}), t.data.interstitialAd.onError(function(e) {
				console.log(e);
			}), t.data.interstitialAd.show().catch(function(e) {
				console.error(e);
			}));
			var o = wx.getSystemInfoSync();
			console.log(6969696), t.data.videoAd = null, a.info.adUnitId && e(o.SDKVersion, "2.6.0") && (t.data.videoAd =
				wx.createRewardedVideoAd({
					adUnitId: a.info.adUnitId
				}), t.data.videoAd.onError(function(e) {
					console.log(e);
				}), t.setData({
					hasVideoAd: !0
				}));
		});
	},
	clearTime: function() {
		console.log(111111), clearTimeout(t.data.setTimeself), clearTimeout(t.data.bagTimeself),
			clearTimeout(t.data.eggTimeself), clearTimeout(t.data.fruitTimeself), console.log(t.data.videoAd);
	},
	onShow: function() {
		this.clearTime(), this.suspension();
		var e = wx.getUpdateManager();
		e.onCheckForUpdate(function(e) {
			console.log(e.hasUpdate);
		}), e.onUpdateReady(function() {
			wx.showModal({
				title: "更新提示",
				content: "新版本已经准备好，是否重启应用？",
				success: function(t) {
					t.confirm && e.applyUpdate();
				}
			});
		}), e.onUpdateFailed(function() {
			wx.showModal({
				title: "更新提示",
				content: "新版本下载失败",
				showCancel: !1
			});
		});
	},
	onUnload: function() {
		this.clearTime();
	},
	onHide: function() {
		this.clearTime();
	},
	videoAdShow: function(e) {
		if (this.data.videoAd) {
			console.log(this.data.videoAd), console.log(99999);
			var a = e.currentTarget.dataset.type;
			this.data.videoAd.show(), t.data.videoAd.offError(function(e) {
				console.log(e);
			}), this.data.videoAd.onClose(function(e) {
				t.data.videoAd.offClose(), (e && e.isEnded || void 0 === e) && (1 == a ? t.selfDouble() : 2 == a ? t.videoAward() :
					3 == a ? t.receiveBag() : 4 == a && t.receiveEgg());
			});
		}
	},
	videoAward: function() {
		var e = {
			action: "video_award",
			contr: "water",
			token: wx.getStorageSync("token"),
			id: t.data.self_water_id
		};
		1 == t.data.request && (t.data.request = 2, a.default.request(e, function(e) {
			t.data.request = 1, t.suspension(), t.setData({
				self_yield_ad_water_show: !1
			}), wx.showToast({
				icon: "none",
				title: "获得" + t.data.video_award_water + "g" + t.data.water_name + "~"
			});
		}));
	},
	selfDouble: function() {
		var e = {
			action: "selfDouble",
			contr: "home",
			token: wx.getStorageSync("token"),
			id: t.data.self_water_id
		};
		1 == t.data.request && (t.data.request = 2, a.default.request(e, function(e) {
			t.setData({
				self_yield_ad_water_show: !1
			}), t.setData(e.info), t.data.request = 1, wx.showToast({
				icon: "none",
				title: "获得" + t.data.self_yield_ad_water + "g" + t.data.water_name + "~"
			});
		}));
	},
	closeSelf: function() {
		t.setData({
			self_yield_ad_water_show: !1
		});
	},
	pest_control: function(e) {
		if (this.data.labour.insect < 1) wx.showToast({
			icon: "none",
			title: "没有虫子啦~"
		});
		else if (parseInt(this.data.insect_water) > parseInt(this.data.member.water)) wx.showToast({
			icon: "none",
			title: t.data.water_name + "不足,无法除虫哦~"
		});
		else if (1 == t.data.request) {
			t.data.request = 2;
			for (var o in this.data.labour.insects)
				if (this.data.labour.insects[o].except) {
					this.data.labour.insects[o].action = !0;
					break;
				}
			this.setData({
				labour: this.data.labour
			});
			var i = {
				action: "labour",
				contr: "home",
				type: 2,
				token: wx.getStorageSync("token")
			};
			a.default.request(i, function(e) {
				2 == e.status ? t.data.request = 1 : setTimeout(function() {
					wx.showToast({
						icon: "none",
						title: "除虫完成,保护果树~"
					}), t.data.request = 1, t.setData(e.info);
				}, 1e3);
			});
		}
	},
	actionWeed: function() {
		if (this.data.labour.weed < 1) wx.showToast({
			icon: "none",
			title: "今日修剪完成,没有枯叶啦~"
		});
		else if (parseInt(this.data.weed_water) > parseInt(this.data.member.water)) wx.showToast({
			icon: "none",
			title: t.data.water_name + "不足,无法修剪哦~"
		});
		else {
			t.data.request = 2;
			for (var e in this.data.labour.weeds)
				if (this.data.labour.weeds[e].except) {
					this.data.labour.weeds[e].action = !0;
					break;
				}
			this.setData({
				labour: this.data.labour
			});
			var o = {
				action: "labour",
				contr: "home",
				type: 1,
				token: wx.getStorageSync("token")
			};
			a.default.request(o, function(e) {
				2 == e.status ? t.data.request = 1 : setTimeout(function() {
					wx.showToast({
						icon: "none",
						title: "修剪完成,保护果树~"
					}), t.data.request = 1, t.setData(e.info);
				}, 1e3);
			});
		}
	},
	receiveSelf: function(e) {
		if (!(this.data.selfYield.surplus > 1)) {
			this.data.self_water_id = this.data.selfYield.id;
			var o = {
				action: "receiveSelf",
				contr: "home",
				token: wx.getStorageSync("token"),
				formid: e.detail.formId
			};
			1 == t.data.request && (t.data.request = 2, a.default.request(o, function(e) {
				t.data.request = 1, t.suspension(), t.data.self_yield_ad_water > 0 && t.data.videoAd ? t.setData({
					self_yield_ad_water_show: !0,
					self_water_number: e.info.water
				}) : wx.showToast({
					icon: "none",
					title: "获得" + e.info.water + "g" + t.data.water_name + "~"
				});
			}));
		}
	},
	suspension: function() {
		var e = {
			action: "suspension",
			contr: "home",
			token: wx.getStorageSync("token")
		};
		"" != t.data.interstitialAd && (t.data.interstitialAd.onError(function(e) {
			console.log(e);
		}), t.data.interstitialAd.show().catch(function(e) {
			console.error(e);
		})), a.default.request(e, function(e) {
			t.setData(e.info), e.info.welfare && t.setData({
					welfare_show: !0
				}), e.info.selfYield ? (clearTimeout(t.data.setTimeself), t.countdown(1)) : t.selfYield(),
				1 == t.data.red_open && (e.info.bag_whether ? (clearTimeout(t.data.bagTimeself),
					t.bagCountdown()) : t.generate(1)), 1 == t.data.egg_open && (e.info.egg_whether ? (clearTimeout(t.data.eggTimeself),
					t.eggCountdown()) : t.generate(2)), e.info.fruiting && (clearTimeout(t.data.fruitTimeself),
					t.fruitCountdown());
		});
	},
	showbagpop: function() {
		this.data.bag_whether.surplus <= 0 && this.setData({
			bagShow: !0
		});
	},
	receiveBag: function() {
		if (1 == t.data.request) {
			t.data.request = 2;
			var e = {
				action: "receive",
				contr: "water",
				token: wx.getStorageSync("token"),
				id: t.data.bag_whether.id
			};
			a.default.request(e, function(e) {
				t.data.request = 1, 1 == e.status && (t.closebag(), t.setData({
					receive_bag_show: !0,
					bag_money: t.data.bag_whether.money
				}), t.setData(e.info), t.suspension());
			});
		}
	},
	receiveEgg: function() {
		if (1 == t.data.request) {
			t.data.request = 2;
			var e = {
				action: "receive",
				contr: "water",
				token: wx.getStorageSync("token"),
				id: t.data.egg_whether.id
			};
			a.default.request(e, function(e) {
				t.data.request = 1, 1 == e.status && (t.hideEgg(), t.setData({
					receive_bag_show: !0,
					bag_money: t.data.egg_whether.money
				}), t.setData(e.info), t.suspension());
			});
		}
	},
	selfYield: function() {
		var e = {
			action: "selfYield",
			contr: "home",
			token: wx.getStorageSync("token")
		};
		a.default.request(e, function(e) {
			1 == e.status && (t.setData(e.info), t.countdown(1));
		});
	},
	generate: function(e) {
		var o = {
			action: "generate",
			contr: "water",
			token: wx.getStorageSync("token"),
			type: e
		};
		a.default.request(o, function(a) {
			1 == a.status && (t.setData(a.info), 1 == e ? t.bagCountdown() : t.eggCountdown());
		});
	},
	countdown: function(e) {
		if (void 0 != this.data.selfYield && this.data.selfYield) {
			var a = t.data.selfYield.surplus;
			t.data.selfYield.surplus--;
			var o = Math.floor(a / 60 / 60 % 24),
				i = Math.floor(a / 60 % 60),
				n = Math.floor(a % 60);
			if (t.data.selfYield.surplus < 0) clearTimeout(t.data.setTimeself);
			else {
				o < 10 && (o = "0" + o), i < 10 && (i = "0" + i), n < 10 && (n = "0" + n);
				t.data.setTimeself = setTimeout(function() {
					t.setData({
						self_i: i,
						self_s: n,
						selfYield: t.data.selfYield
					}), t.countdown();
				}, 1e3);
			}
		} else clearTimeout(t.data.setTimeself);
	},
	bagCountdown: function() {
		var e = t.data.bag_whether.surplus;
		t.data.bag_whether.surplus--;
		var a = Math.floor(e / 60 / 60 % 24),
			o = Math.floor(e / 60 % 60),
			i = Math.floor(e % 60);
		if (t.data.bag_whether.surplus < 0) clearTimeout(t.data.bagTimeself);
		else {
			a < 10 && (a = "0" + a), o < 10 && (o = "0" + o), i < 10 && (i = "0" + i);
			t.data.bagTimeself = setTimeout(function() {
				t.setData({
					bag_i: o,
					bag_s: i,
					bag_whether: t.data.bag_whether
				}), t.bagCountdown();
			}, 1e3);
		}
	},
	fruitCountdown: function() {
		if (void 0 != this.data.fruiting && this.data.fruiting) {
			var e = t.data.fruiting.surplus;
			t.data.fruiting.surplus--;
			var o = Math.floor(e / 60 / 60 % 24),
				i = Math.floor(e / 60 % 60),
				n = Math.floor(e % 60);
			if (t.data.fruiting.surplus < 0) {
				t.data.fruitTimeself && clearTimeout(t.data.fruitTimeself);
				var s = {
					action: "transform",
					contr: "fruit",
					token: wx.getStorageSync("token"),
					id: t.data.fruiting.id
				};
				a.default.request(s, function(e) {
					1 == e.status && t.suspension();
				});
			} else {
				o < 10 && (o = "0" + o), i < 10 && (i = "0" + i), n < 10 && (n = "0" + n);
				t.data.fruitTimeself = setTimeout(function() {
					t.setData({
						fruit_i: i,
						fruit_s: n,
						fruiting: t.data.fruiting
					}), t.fruitCountdown();
				}, 1e3);
			}
		} else clearTimeout(t.data.fruitTimeself);
	},
	eggCountdown: function() {
		if (void 0 != this.data.egg_whether && this.data.egg_whether) {
			var e = t.data.egg_whether.surplus;
			t.data.egg_whether.surplus--;
			var a = Math.floor(e / 60 / 60 % 24),
				o = Math.floor(e / 60 % 60),
				i = Math.floor(e % 60);
			if (t.data.egg_whether.surplus < 0) clearTimeout(t.data.eggTimeself);
			else {
				a < 10 && (a = "0" + a), o < 10 && (o = "0" + o), i < 10 && (i = "0" + i);
				t.data.eggTimeself = setTimeout(function() {
					t.setData({
						egg_i: o,
						egg_s: i,
						egg_whether: t.data.egg_whether
					}), t.eggCountdown();
				}, 1e3);
			}
		} else clearTimeout(t.data.eggTimeself);
	},
	signIn: function(e) {
		var o = {
			action: "siginIn",
			contr: "sigin",
			token: wx.getStorageSync("token"),
			formid: e.detail.formId
		};
		1 == t.data.request && (t.data.request = 2, a.default.request(o, function(e) {
			t.data.request = 1, t.setData({
				signin_days: e.info
			}), wx.navigateTo({
				url: "/bh_farm/pages/sign/sign"
			});
		}));
	},
	openRed: function(e) {
		var o = e.currentTarget.dataset.index,
			i = {
				action: "shareBag",
				contr: "water",
				token: wx.getStorageSync("token"),
				index: o
			};
		1 == t.data.request && (t.data.request = 2, a.default.request(i, function(e) {
			t.data.request = 1, 1 == e.status ? t.setData(e.info) : wx.showModal({
				title: "提示",
				mask: !0,
				content: e.info,
				showCancel: !1
			});
		}));
	},
	extract: function(e) {
		var o = e.currentTarget.dataset.id,
			i = {
				action: "extract",
				contr: "fruit",
				token: wx.getStorageSync("token"),
				id: o
			};
		1 == t.data.request && (t.data.request = 2, a.default.request(i, function(e) {
			t.data.request = 1, 1 == e.status && t.suspension();
		}));
	},
	extractCommission: function(e) {
		var o = e.currentTarget.dataset.id,
			i = {
				action: "commission",
				contr: "fruit",
				token: wx.getStorageSync("token"),
				id: o
			};
		1 == t.data.request && (t.data.request = 2, a.default.request(i, function(e) {
			t.data.request = 1, t.suspension();
		}));
	},
	goMessageList: function() {
		var e = o.siteInfo.siteroot + "?i=" + o.siteInfo.uniacid +
			"&from=wxapp&c=entry&a=wxapp&do=questionList&m=bh_prise";
		wx.setStorageSync("discovery_h5url", e), wx.navigateTo({
			url: "/bh_prise/pages/discoveryH5/discoveryH5"
		});
	},
	onShareAppMessage: function() {
		return {
			title: this.data.share.text,
			imageUrl: this.data.share.images,
			path: "bh_farm/pages/index/index?parent_id=" + this.data.share.member_id
		};
	},
	getUserInfo: function(e) {
		if ("getUserInfo:ok" == e.detail.errMsg) {
			var o = {
				action: "register",
				contr: "home",
				token: wx.getStorageSync("token"),
				encryptedData: e.detail.encryptedData,
				iv: e.detail.iv
			};
			a.default.request(o, function(e) {
				t.onReady();
			});
		}
	},
	adError: function(e) {
		console.log(e);
	},
	closebag: function() {
		t.setData({
			bagShow: !1
		});
	},
	hideReceiveBag: function() {
		t.setData({
			receive_bag_show: !1
		});
	},
	hideInviteRed: function() {
		t.setData({
			invite_red_show: !1
		});
	},
	shoWShareBag: function() {
		t.setData({
			invite_red_show: !0
		});
	},
	hideEgg: function() {
		t.setData({
			showEgg: !1
		});
	},
	showEgg: function() {
		t.data.egg_whether.surplus <= 0 && t.setData({
			showEgg: !0
		});
	},
	hideHelp: function() {
		t.setData({
			showHelp: !1
		});
	},
	inviteAccelerate: function() {
		t.setData({
			showHelp: !0
		});
	},
	hidewWelfare: function() {
		t.setData({
			welfare_show: !1
		});
	},

});
